#include "taskQueue.h"

int taskQueueInit(taskQueue_t* p_taskQueue){
    bzero(p_taskQueue,sizeof(taskQueue_t));
    return 0;
}

int enqueue(taskQueue_t* p_taskQueue,int netfd,TLV_t* tlv){
    node_t* new_node = (node_t*)calloc(1,sizeof(node_t));
    new_node->netfd = netfd;
    memcpy(&new_node->tlv,tlv,sizeof(TLV_t));
    if(p_taskQueue->cursize == 0){
        p_taskQueue->front = new_node;
        p_taskQueue->rear = new_node;
    }
    else{
        p_taskQueue->rear->next = new_node;
        p_taskQueue->rear = new_node;
    } 
    ++p_taskQueue->cursize;
    return 0;
}

int dequeue(taskQueue_t* p_taskQueue){
    node_t* cur = p_taskQueue->front;
    p_taskQueue->front = cur->next;
    if(p_taskQueue->cursize == 1){
        p_taskQueue->rear = NULL;
    }
    --p_taskQueue->cursize;
    free(cur);
    return 0;
}
